﻿using System.Web;
using ABC.Business.Models;
using ABC.Core.Configuration;
using ABC.Core.Providers;

namespace ABC.Controllers.ViewModels
{
    public class BaseViewModel
    {
        private Domain.Entities.User currentUser;
        private readonly UserModel userModel;
        private readonly IApplicationSettingsProvider applicationSettingsProvider;

        public BaseViewModel()
        {
            userModel = IoC.Resolve<UserModel>();
            applicationSettingsProvider = IoC.Resolve<IApplicationSettingsProvider>();
        }

        public string YandexMetrikaId
        {
            get { return applicationSettingsProvider.YandexMetrikaId; }
        }

        public string CurrentControllerName
        {
            get { return HttpContext.Current.Request.RequestContext.RouteData.Values["controller"].ToString().ToLower(); }

        }
        public string CurrentActionName
        {
            get
            {
                return HttpContext.Current.Request.RequestContext.RouteData.Values["action"].ToString().ToLower();
            }
        }
        public Domain.Entities.User CurrentUser
        {
            get
            {
                if (currentUser == null && HttpContext.Current.User != null && !string.IsNullOrEmpty(HttpContext.Current.User.Identity.Name))
                {
                    currentUser = userModel.GetUser(HttpContext.Current.User.Identity.Name);
                }
                return currentUser;
            }
        }

    }
}